package com.xbongbong.paas.pojo;

import com.xbongbong.pro.custombutton.pojo.CustomButtonActionPojo;
import com.xbongbong.saas.enums.ListOptionTabEnum;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/1/24 11:27
 * @since v1.0
 */
@Setter
@Getter
public class ButtonPojo implements Cloneable{

    /**
     * 按钮唯一键
     */
    private String buttonId;

    /**
     * 按钮名
     */
    private String attr;
    /**
     * 按钮展示名称
     */
    private String value;
    /**
     * 按钮样式
     */
    private String type;
    /**
     * 图标
     */
    private String icon;

    private Long formId;
    /**
     * 是否禁用
     */
    private Integer disabled;

    /**
     * 是否需要提示
     */
    private Integer needRemind;

    /**
     * 是否需要提示
     */
    private String remindMsg;

    /**
     * 业务类型
     */
    private Integer linkBusinessType;

    private ButtonExtraPojo buttonExtra;
    /**
     * 子按鈕數組
     */
    private List<ButtonPojo> subButtons;

    /**
     * 关联列
     */
    private String linkAttr;

    /**
     * 关联列
     */
    private String actions;

    /**
     * 低代码，按钮动作
     */
    private List<CustomButtonActionPojo> actionList;

    /**
     * 图表分类id
     */
    private Long categoryId;

    /**
     * 图标分类的parentId
     */
    private Long parentId;

    private Integer distributorMark;

    public ButtonPojo() {
        this.needRemind = 0;
    }

    public ButtonPojo(ListOptionTabEnum listOptionTabEnum) {
        this.attr = listOptionTabEnum.getAttr();
        this.value = listOptionTabEnum.getAttrName();
        this.disabled = 0;
        this.needRemind = 0;
    }

    public ButtonPojo(ListOptionTabEnum listOptionTabEnum, int businessType) {
        this.attr = listOptionTabEnum.getAttr();
        this.value = listOptionTabEnum.getAttrName();
        this.disabled = 0;
        this.needRemind = 0;
        ButtonExtraPojo buttonExtraPojo = new ButtonExtraPojo();
        buttonExtraPojo.setBusinessType(businessType);
        this.buttonExtra = buttonExtraPojo;
    }
    public ButtonPojo(ListOptionTabEnum listOptionTabEnum, int businessType, Integer distributorMark) {
        this.attr = listOptionTabEnum.getAttr();
        this.value = listOptionTabEnum.getAttrName();
        this.disabled = 0;
        this.needRemind = 0;
        ButtonExtraPojo buttonExtraPojo = new ButtonExtraPojo();
        buttonExtraPojo.setBusinessType(businessType);
        this.buttonExtra = buttonExtraPojo;
        this.distributorMark = distributorMark;
    }

    public ButtonPojo(ListOptionTabEnum listOptionTabEnum, int businessType, String linkAttr) {
        this.attr = listOptionTabEnum.getAttr();
        this.value = listOptionTabEnum.getAttrName();
        this.disabled = 0;
        this.needRemind = 0;
        ButtonExtraPojo buttonExtraPojo = new ButtonExtraPojo();
        buttonExtraPojo.setBusinessType(businessType);
        this.buttonExtra = buttonExtraPojo;
        this.linkAttr = linkAttr;
    }

    public void addBusinessType(int businessType) {
        this.buttonExtra = buttonExtra == null ? new ButtonExtraPojo() : buttonExtra;
        buttonExtra.setBusinessType(businessType);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static List<ButtonPojo> deepClone(List<ButtonPojo> buttonPojoList){
        List<ButtonPojo> depButtonPojoList = new ArrayList<>();
        for (ButtonPojo buttonPojo : buttonPojoList){
            try {
                depButtonPojoList.add((ButtonPojo)buttonPojo.clone());
            } catch (CloneNotSupportedException e) {
                e.printStackTrace();
            }
        }
        return depButtonPojoList;
    }
}
